cmake_minimum_required(VERSION 3.0)

project(common)

message("CMAKE_HOST_SYSTEM_NAME: ${CMAKE_HOST_SYSTEM_NAME}")
# 平台检测，或者指定编译工具链等
if(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux")
    set(IS_LINUX 1)
else()
    #默认为windows的mingw64平台
    set(IS_WINDOWS 1)
endif()

file(GLOB_RECURSE SRC_LIST ./*.cpp ./*.cc ./*.cxx ./*.c ./*.h ./*.hpp)

include_directories(${PROJECT_SOURCE_DIR})
include_directories(${PROJECT_SOURCE_DIR}/xmlhelper)
include_directories(${PROJECT_SOURCE_DIR}/jsonbean)
include_directories(${PROJECT_SOURCE_DIR}/../../thirdparty/inc)

set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/../../bin)
add_library(${PROJECT_NAME} SHARED ${SRC_LIST})

if(0)
#暂时列从可支持编译平台
if(${BUILD_PLATFORM} MATCHES "linux-arm")
    #linux-arm平台
else()
    #if(CMAKE_SYSTEM_NAME MATCHES "Windows")  #windows平台
    if(${BUILD_PLATFORM} MATCHES "windows")
        #windows平台
        target_link_libraries(${PROJECT_NAME} pthread m)
    else()
        #linux-x86平台
        target_link_libraries(${PROJECT_NAME} dl rt m pthread)
    endif()
endif()
else()
    if(IS_WINDOWS)
    #if(CMAKE_SYSTEM_NAME MATCHES "Windows")  #windows平台
        #windows平台
        file(GLOB_RECURSE SQLITE3_LIB ${PROJECT_SOURCE_DIR}/../../thirdparty/lib/win/sqlite3/*.dll)
        target_link_libraries(${PROJECT_NAME} ${SQLITE3_LIB} pthread m)
    else()
        #linux-x86平台
        file(GLOB_RECURSE SQLITE3_LIB ${PROJECT_SOURCE_DIR}/../../thirdparty/lib/linux/sqlite3/*.so)
        target_link_libraries(${PROJECT_NAME} ${SQLITE3_LIB} pthread dl rt m)
    endif()
endif()
